<?php
/*
* 业绩展示
*/
/** * * ━━━━━━神兽出没━━━━━━
*       ┌─┐      ┌─┐
*     ┌─┘─┴──────┘─┴─┐
*     │              │
*     │      ─       │
*     │  ┬─┘   └─┬   │
*     │              │
*     │      ┴       │
*     │              │
*     └───┐      ┌───┘
*         │      │Code is far away from bug with the animal protecting ！
*         │      │神兽保佑,代码无bug！ 
*         │      └──────┐
*         │             ├┐
*         │             ┌┘
*         └┐ ┐ ┌───┬─┐ ┌┘
*          │ ┤ ┤   │ ┤ ┤
*          └─┴─┘   └─┴─┘
* ━━━━━━感觉萌萌哒━━━━━━
*/ 
namespace app\admin\controller;
use think\Controller;
use think\Request;
use \think\Db;
class Performance extends Base{

     //业绩列表
     public function index(){ 
       $data = $this->data;
       $where = [ 'ischeck'=>1,'del_status'=>0];
       $field = "id,name";
       $list = Db::name("shop")->where($where)->field($field)->paginate(10); 
       if(!empty($list)){
        $datas = $list->all();  
        $end_time = time();
        $start_time = time()-7*3600;
        $get_where = '';
        if(isset($data['time_type'])){
          switch ($data['time_type']) {
            case 1: $start = time()-3*3600; break; //三天
            case 2: $start = time()-7*3600; break; //一周
            case 3: $start = time()-30*3600; break; //一月
            case 4: $start = $data['start_time'];$end_time = $data['end_time']; break; //自定义 
            break;
          }
          $get_where = "addtime between {$start_time} AND  {$end_time} ";
        }
        foreach ($datas as $key => $value) {  
          $value['order_num'] = Db::name(self::$tb['order'])->where($get_where)->count();
          $value['order_total'] = Db::name(self::$tb['order'])->where($get_where)->sum("paid_price");
          $value['user_num'] = Db::name(self::$tb['user'])->where("addtime between {$start_time} AND  {$end_time} and role_id = 1 and shop_id =".$value['id'])->count();
          $value['user_flow'] = Db::name(self::$tb['user'])->where("addtime between {$start_time} AND  {$end_time} and role_id = 1 and shop_id =".$value['id'])->sum("flow_money");
          $list[$key] = $value;
        }    
      }
      $page = $list->render();
      $this->assign("list",$list);
      $this->assign("page",$page); 
       // $this->assign('list',$list);
       return $this->fetch();
     }

     

}
